<?php
namespace app\zhonghang\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;
class System extends Base {
//    关于我们
    public function aboutme()
    {
        $res = DB::name('config')->where('name',jieshao)->value('value');
        if($res)
        {
            $data['info'] = '取值成功';
            $data['status'] = '1';
            $data['data'] = $res;
            return json($data);
        }else{
            $data['info'] = '取值失败';
            $data['status'] = '-1';
            $data['data'] = array();
            return json($data);
        }
    }

//    常见问题
    public function problem()
    {
        $res = DB::name('config')->where('name',question)->value('value');
        if($res)
        {
            $data['info'] = '取值成功';
            $data['status'] = '1';
            $data['data'] = $res;
            return json($data);
        }else{
            $data['info'] = '取值失败';
            $data['status'] = '-1';
            $data['data'] = array();
            return json($data);
        }
    }

//    使用指南
    public function zhinan()
    {
        $res = DB::name('config')->where('name',zhinan)->value('value');
        if($res)
        {
            $data['info'] = '取值成功';
            $data['status'] = '1';
            $data['data'] = $res;
            return json($data);
        }else{
            $data['info'] = '取值失败';
            $data['status'] = '-1';
            $data['data'] = array();
            return json($data);
        }
    }

//    个人资料
//      修改昵称
    public function nickname()
    {
        $member = $this->member;
        $data['nickname'] = input('nickname');
        $res = DB::name('Users')->where('user_id',$member['user_id'])->update($data);
        if($res)
        {
            $data['info'] = '修改成功';
            $data['status'] = '1';
            $data['data'] = array();
            return json($data);
        }else{
            $data['info'] = '修改失败';
            $data['status'] = '-1';
            $data['data'] = array();
            return json($data);
        }
    }

//    修改头像
    public function editHead()
    {
        $member = $this->member;
        $image=input('zpic');
        $imageName = rand(1000,100000).time().'.png';
        if (strstr($image,",")){
            $image = explode(',',$image);
            $image = $image[1];
        }
        $path = "/public/uploads/real";
        $imageSrc= $path."/". $imageName; //图片名字
        $r = file_put_contents(ROOT_PATH.$imageSrc, base64_decode($image));
        $arr['head_pic']=$imageSrc;
        $res = DB::name('Users')->where('user_id',$member['user_id'])->update($arr);
        if($res)
        {
            $data['info'] = '修改头像成功';
            $data['status'] = '1';
            $data['data'] = $res;
            return json($data);
        }else{
            $data['info'] = '修改头像失败';
            $data['status'] = '-1';
            $data['data'] = array();
            return json($data);
        }
    }
}